package com.youdoneed.community.forum.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.youdoneed.community.common.vo.PageData;
import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forum.entity.Forumsystemrecommenduser;
import com.youdoneed.community.forum.service.ForumsystemrecommenduserService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 系统推荐用户控制器
 *
 * @author lixs
 * @Date 2016.6.19
 */

@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "/forumsystemrecommenduser", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "论坛评论模块控制器", description = "论坛评论模块相关操作")
public class ForumsystemrecommenduserController {
    private static final Logger logger = LoggerFactory.getLogger(ForumsystemrecommenduserController.class);

    @Autowired
    ForumsystemrecommenduserService forumsystemrecommenduserService;

    /**
     * 获取所有系统推荐用户
     *
     * @return ResultMessage
     * @author lixs
     * @Date 2017.6.19
     */
    @RequestMapping(value = "/getAllRecommendUsers", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "获取所有推荐用户", value = "获取所有推荐用户")
    public ResultMessage<PageData> getAllRecommendUsers(int limit, int offset) {
        logger.info("获取所有推荐用户");
        List<Forumsystemrecommenduser> forumsystemrecommenduser = forumsystemrecommenduserService.getAllRecommendUsers(limit, offset);
//		Map<String, Object> mapResult = new HashMap<String, Object>();
//		mapResult.put("rows", forumsystemrecommenduser);
//		
//		logger.info("获取用户总数");
//		int total = forumsystemrecommenduserService.countTotalCommendUser();
//		logger.info("total:"+total);
//		
//		mapResult.put("total", total);
        PageData page = new PageData();
        page.setRows(forumsystemrecommenduser);
        page.setTotal(forumsystemrecommenduserService.countTotalCommendUser());
        if (forumsystemrecommenduser != null) {
            return ResultMessage.newSuccess("获取所有推荐用户成功!").setData(page);
        }
        return ResultMessage.newFailure("获取所有推荐用户失败!");
    }

    /**
     * 删除系统推荐用户
     *
     * @param id
     * @return
     * @author lixs
     * @Date 2017.6.19
     */
    @RequestMapping(value = "/deleteForumsystemrecommenduser", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "删除系统推荐用户", value = "删除系统推荐用户")
    public ResultMessage<Integer> deleteForumsystemrecommenduser(String id) {
        logger.info("通过id" + id + "删除系统推荐用户");
        int forumsystemrecommenduser = forumsystemrecommenduserService.deleteForumsystemrecommenduser(id);
        return ResultMessage.newSuccess("删除系统推荐用户！").setData(forumsystemrecommenduser);

    }

    /**
     * 保存系统推荐用户
     *
     * @param user
     * @return
     * @author lixs
     * @Date 2017.6.19
     */
    @RequestMapping(value = "/saveForumsystemrecommenduser", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "保存系统推荐用户", value = "保存系统推荐用户")
    public ResultMessage<Integer> saveForumsystemrecommenduser(Forumsystemrecommenduser user) {
        logger.info("保存系统推荐用户");
        if (user == null) {
            logger.info("user参数为空");
        }
        int forumsystemrecommenduser = forumsystemrecommenduserService.saveForumsystemrecommenduser(user);
        return ResultMessage.newSuccess("保存系统推荐用户！").setData(forumsystemrecommenduser);
    }

    /**
     * 根据条件查询系统推荐用户列表
     *
     * @param nickname
     * @param createdateS
     * @param createdateE
     * @param limit
     * @param offset
     * @return ResultMessage
     * @author lixs
     * @Date 2017.6.23
     */
    @RequestMapping(value = "/queryRecommendUsersByPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "根据条件查询统推荐用户", value = "根据条件查询统推荐用户")
    public ResultMessage<PageData> queryRecommendUsersByPage(String nickname, String createdateS, String createdateE, int limit, int offset) {
        logger.info("根据条件查询统推荐用户");
        List<Forumsystemrecommenduser> forumsystemrecommenduser = forumsystemrecommenduserService.queryRecommendUsersByPage(nickname, createdateS, createdateE, limit, offset);
        List<Forumsystemrecommenduser> systemrecommenduser = forumsystemrecommenduserService.queryRecommendUsers(nickname, createdateS, createdateE);
//		Map<String, Object> mapResult = new HashMap<String, Object>();
//		mapResult.put("rows", forumsystemrecommenduser);
//		
//		logger.info("获取用户总数");
//		int total = systemrecommenduser.size();
//		logger.info("total:"+total);
//		
//		mapResult.put("total", total);
        PageData page = new PageData();
        page.setRows(forumsystemrecommenduser);
        page.setTotal(systemrecommenduser.size());
        if (forumsystemrecommenduser != null) {
            return ResultMessage.newSuccess("获取条件查询推荐用户成功!").setData(page);
        }
        return ResultMessage.newFailure("获取条件查询推荐用户失败!");
    }

    /**
     * 修改系统推荐用户信息
     *
     * @param record
     * @author lixs
     * @Date 2017.6.23
     */
    @RequestMapping(value = "/updateByPrimaryKeySelective", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "修改系统推荐用户信息", value = "修改系统推荐用户信息")
    public ResultMessage<Integer> updateByPrimaryKeySelective(Forumsystemrecommenduser record) {
        logger.info("修改系统推荐用户信息");
        int forumsystemrecommenduser = forumsystemrecommenduserService.updateByPrimaryKeySelective(record);
        return ResultMessage.newSuccess("修改系统推荐用户信息！").setData(forumsystemrecommenduser);

    }
}
